
package com.jf.cloud.live.controller.app;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.live.dto.LiveUserDTO;
import com.jf.cloud.live.model.LiveUser;
import com.jf.cloud.live.service.LiveUserService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 直播成员
 *
 * @author zz
 * @date 2022-08-17 17:09:06
 */
@RestController("appLiveUserController")
@RequestMapping("/live_user")
@Tag(name = "直播成员")
public class LiveUserController {

    @Autowired
    private LiveUserService liveUserService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取直播成员列表" , description = "分页获取直播成员列表")
    public ServerResponseEntity<PageVO<LiveUser>> page(@Valid PageDTO pageDTO, @ParameterObject LiveUserDTO liveUserDTO) {
        PageVO<LiveUser> liveUserPage = liveUserService.page(pageDTO, liveUserDTO);
        return ServerResponseEntity.success(liveUserPage);
    }

    @GetMapping
    @Operation(summary = "获取直播成员" , description = "根据liveUserId获取直播成员")
    public ServerResponseEntity<LiveUser> getByLiveUserId(@ParameterObject @RequestParam Long liveUserId) {
        return ServerResponseEntity.success(liveUserService.getByLiveUserId(liveUserId));
    }

    @PostMapping
    @Operation(summary = "保存直播成员" , description = "保存直播成员")
    public ServerResponseEntity<Void> save(@Valid @RequestBody LiveUserDTO liveUserDTO) {
        LiveUser liveUser = mapperFacade.map(liveUserDTO, LiveUser.class);
        liveUserService.save(liveUser);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新直播成员" , description = "更新直播成员")
    public ServerResponseEntity<Void> update(@Valid @RequestBody LiveUserDTO liveUserDTO) {
        LiveUser liveUser = mapperFacade.map(liveUserDTO, LiveUser.class);
        liveUserService.update(liveUser);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除直播成员" , description = "根据直播成员id删除直播成员")
    public ServerResponseEntity<Void> delete(@RequestParam Long liveUserId) {
        liveUserService.deleteById(liveUserId);
        return ServerResponseEntity.success();
    }
}
